import { Entity, Column, PrimaryGeneratedColumn, UpdateDateColumn, ManyToOne, JoinColumn, OneToMany } from 'typeorm';
import { ApiProperty} from '@nestjs/swagger';
import {
  IsOptional,
  IsString,
  MaxLength,
  MinLength,
  IsNotEmpty,
  IsEmail,
  IsPhoneNumber,
  IsDate,
  ValidateNested
} from "class-validator";
import { Brand } from './brand.entities';
import { Category } from './category.entity';
import { GoodsAttribute } from './goods_attribute.entity';
import { Footprint } from './footprint.entities';
import { GoodsSpecification } from './goods_specification.entity';
import { Product } from './product.entities';
import { OrderGoods } from './order_goods.entities';
import { CouponGoods } from './coupon_goods.entity';

@Entity()
export class Goods {
  @PrimaryGeneratedColumn()
  id: number;

  @IsOptional()
  @ApiProperty()
  @Column({type: 'int', width: 11})
  category_id: number;

  @IsOptional()
  @ApiProperty()
  @Column({type: 'int', width: 11})
  brand_id: number;

  @IsOptional()
  @ApiProperty()
  @Column({type: 'tinyint', width: 1})
  is_on_sale: number;

  @IsOptional()
  @ApiProperty()
  @Column({type: 'smallint', width: 4})
  sort_order: number;

  @IsOptional()
  @ApiProperty()
  @Column({type: 'tinyint', width: 1})
  is_delete: number;

  @IsOptional()
  @ApiProperty()
  @Column({type: 'tinyint', width: 1})
  is_new: number;

  @IsOptional()
  @ApiProperty()
  @Column({type: 'int', width: 11})
  attribute_category: number;

  @IsOptional()
  @ApiProperty()
  @Column({type: 'mediumint', width: 8})
  goods_number: number;

  @IsOptional()
  @ApiProperty()
  @Column({type: 'varchar' ,length: 60 })
  goods_sn: string;

  @IsOptional()
  @ApiProperty()
  @Column({type: 'varchar' ,length: 255 })
  keywords: string;

  @IsOptional()
  @ApiProperty()
  @Column({type: 'varchar' ,length: 255 })
  goods_brief: string;

  @IsOptional()
  @ApiProperty()
  @Column({type: 'varchar' ,length: 120 })
  name: string;

  @IsOptional()
  @ApiProperty()
  @Column('text')
  goods_desc: string;

  @IsOptional()
  @ApiProperty()
  @Column({type: 'varchar' ,length: 45 })
  goods_unit: string;

  @IsOptional()
  @ApiProperty()
  @Column({type: 'varchar' ,length: 255 })
  primary_pic_url: string;

  @IsOptional()
  @ApiProperty()
  @Column({type: 'varchar' ,length: 255 })
  list_pic_url: string;

  @IsOptional()
  @ApiProperty()
  @Column({type: 'varchar' ,length: 255 })
  promotion_desc: string;

  @IsOptional()
  @ApiProperty()
  @Column({type: 'varchar' ,length: 45 })
  promotion_tag: string;

  @IsOptional()
  @ApiProperty()
  @Column({type: 'decimal', width: 10})
  market_price: number;

  @IsOptional()
  @ApiProperty()
  @Column({type: 'decimal', width: 10})
  unit_price: number;

  @IsOptional()
  @ApiProperty()
  @Column({type: 'decimal', width: 10})
  retail_price: number;

  @IsOptional()
  @ApiProperty()
  @Column({type: 'decimal', width: 10})
  counter_price: number;

  @IsOptional()
  @ApiProperty()
  @Column({type: 'decimal', width: 10})
  extra_price: number;

  @IsOptional()
  @ApiProperty()
  @Column({type: 'int', width: 11})
  sell_volume: number;

  @IsOptional()
  @ApiProperty()
  @Column({type: 'int', width: 11})
  primary_product_id: number;

  @IsOptional()
  @ApiProperty()
  @Column({type: 'decimal', width: 10})
  app_exclusive_price: number;

  @IsOptional()
  @ApiProperty()
  @Column({type: 'tinyint', width: 1})
  is_app_exclusive: number;

  @IsOptional()
  @ApiProperty()
  @Column({type: 'tinyint', width: 1})
  is_limited: number;

  @IsOptional()
  @ApiProperty()
  @Column({type: 'tinyint', width: 1})
  is_hot: number;

  @IsOptional()
  @ApiProperty()
  @Column({type: 'bigint', width: 20})
  create_user_id: number;

  @IsOptional()
  @ApiProperty()
  @Column({type: 'bigint', width: 20})
  update_user_id: number;

  @IsOptional()
  @ApiProperty()
  @Column({type: 'bigint', width: 20})
  create_user_dept_id: number;

  @IsOptional()
  @ApiProperty()
  @UpdateDateColumn()
  add_time: Date;

  @IsOptional()
  @ApiProperty()
  @UpdateDateColumn()
  update_time: Date

  @ManyToOne(type => Brand, brand => brand.goods)
  @JoinColumn({
    name:"brand_id"
  })
  brand: Brand

  @ManyToOne(type => Category, category => category.goods)
  @JoinColumn({
    name:"category_id"
  })
  category: Category[]

  @OneToMany(type => Footprint, footprint => footprint.goods)
  @JoinColumn({
    name:"category_id"
  })
  footprint: Footprint[]

  @OneToMany(type => GoodsAttribute, goodsAttribute => goodsAttribute.goods)
  goodsAttribute: GoodsAttribute[]

  @OneToMany(type => GoodsSpecification, goodsSpecification => goodsSpecification.goods)
  goodsSpecification: GoodsSpecification[]

  @OneToMany(type => Product,product => product.goods)
  product:Product[]

  @OneToMany(type => OrderGoods,orderGoods => orderGoods.goods)
  orderGoods:OrderGoods[]

  @OneToMany(type => CouponGoods,couponGoods => couponGoods.goods)
  couponGoods:CouponGoods[]
}
